#!/bin/bash
########################################
#  This file is part of the open-eBackup project.
# Copyright (c) 2024 Huawei Technologies Co.,Ltd.
#
# open-eBackup is licensed under MPL v2.
# You can use this software according to the terms and conditions of the MPL v2.
# You may obtain a copy of MPL v2 at:
#
#          https://www.mozilla.org/en-US/MPL/2.0
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the MPL v2 for more details.
########################################

set -eux
set -o pipefail

install_dir=$1
[ -d "${install_dir}" ] && rm -rf ${install_dir}
mkdir -p ${install_dir}

if [ -z "$(uname -a | grep aarch64)" ];then
    unzip -o x86/apache-ant-1.10.12-bin.zip
else
    unzip -o arch/apache-ant-1.10.12-bin.zip
fi

cp -fr apache-ant-1.10.12/* ${install_dir}

#set env
sed -i '/ANT_HOME/d' /etc/profile
echo "export ANT_HOME=${install_dir}" >> /etc/profile
echo 'export CLASSPATH=$ANT_HOME/lib:$CLASSPATH' >> /etc/profile
echo 'export PATH=$ANT_HOME/bin:$PATH' >> /etc/profile


ln -fs ${install_dir}/bin/ant /usr/local/bin/ant
ln -fs ${install_dir}/bin/antRun /usr/local/bin/antRun
ln -fs ${install_dir}/bin/antRun.pl /usr/local/bin/antRun.pl
ln -fs ${install_dir}/bin/complete-ant-cmd.pl /usr/local/bin/complete-ant-cmd.pl
ln -fs ${install_dir}/bin/runant.pl /usr/local/bin/runant.pl
ln -fs ${install_dir}/bin/runant.py /usr/local/bin/runant.py
